package com.fjzx.androidframe.base.util;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions;
import com.bumptech.glide.request.RequestOptions;

/**
 * 图片加载器
 *
 * @author xiongyongcong
 */
public class XImageLoader {

    public static void cancel(Context context, ImageView imageView) {
        Glide.with(context).clear(imageView);
    }

    /**
     * 加载图片
     *
     * @param imageView ImageView
     * @param url       图片地址
     */
    public static void load(ImageView imageView, String url) {
        Glide.with(imageView)
                .load(url)
                .transition(DrawableTransitionOptions.withCrossFade())
                .into(imageView);
    }

    public static void load(ImageView imageView, String url, int placeholder) {
        Glide.with(imageView)
                .load(url)
                .transition(DrawableTransitionOptions.withCrossFade())
                .into(imageView);
    }

    public static void load(ImageView imageView, String url, int placeholder, int error) {
        RequestOptions options = new RequestOptions().placeholder(placeholder)
                .error(error).fitCenter();
        Glide.with(imageView)
                .load(url)
                .apply(options)
                .transition(DrawableTransitionOptions.withCrossFade())
                .into(imageView);
    }

    public static void loadVideo(ImageView imageView, String url) {
        load(imageView, url);
    }
}
